
<template>
  <div class="second-contrainer">
    <div class="video-title">
      <span>{{ video.videoName }}</span>
    </div>
    <div class="line"></div>
    <div class="top-contrainer">
      <div class="top-left">
        <div class="video-img">
          <img
            @click="play(video.videoSign, video.videoName, video.videoId)"
            :src="video.videoCover"
            alt=""
          />
        </div>
      </div>
      <div class="top-right">
        <span
          >豆瓣评分：<span class="score"
            >{{ randomNum(6, 9) }}.{{ randomNum(0, 9) }}</span
          >分</span
        >
        <p style="text-indent: 2em">
          {{ video.videoIntro }}
        </p>
      </div>
    </div>
    <div class="middle-contrainer">
      <el-tabs style="margin-top: 30px" v-model="activeName1" type="card">
      </el-tabs>
      <el-tabs style="margin-top: 30px" v-model="activeName2" type="card">
        <el-tab-pane :label="`<${video.videoName}>评论`" name="first">
          <div class="comments">
            <div
              class="comment-item"
              style="padding-top: 10px; line-height: 25px;
              font-family:serif;
              "
              v-for="i in video.videoCommontEntityList"
              :key="i"
            >
              <span style="font-size: 16px; font-weight: bold; color: #67c23a"
                ><i class="el-icon-user" style="margin-right: 10px"></i
                >{{ i.userEntity.username }}：</span
              >{{ i.commontText }}
            </div>
          </div>
          <el-empty :image-size="50" description="暂无评论" v-if="!video.videoCommontEntityList.length"></el-empty>
          <div class="submit-comment">
            <textarea
              placeholder="输入评论"
              v-model="comment"
              name="comment"
              id=""
              cols="30"
              rows="8"
              style="font-size: 16px"
            ></textarea>
          </div>
          <el-button
            type="primary"
            style="width: 100%; margin-bottom: 10px"
            @click="submitComment"
            >发布</el-button
          >
        </el-tab-pane>
      </el-tabs>
    </div>
  </div>
</template>
<script>
import { getOneFilm, submitComment } from "../../api/video";
export default {
  name: "Second",
  data() {
    return {
      value: null,
      comment: "",
      video: {},
      id: undefined,
      activeName: "first",
      activeName1: "first",
      activeName2: "first",
    };
  },
  computed: {
    test1() {
      return Array.from(this.test).reverse();
    },
  },
  methods: {
    play(sign, name, id) {
      this.$router.push({
        path: "play",
        query: {
          sign,
          name,
          id,
        },
      });
    },
    submitComment() {
      if (localStorage.getItem("u_id")) {
        if (this.comment) {
          submitComment({
            userId: parseInt(localStorage.getItem("u_id")),
            videoId: this.video.videoId,
            commontText: this.comment,
          }).then((res) => {
            if (res.data.code == 0) {
              this.$message.success("发表成功！");
              getOneFilm(this.$route.query.v_id).then((res) => {
                  this.video = res.data.video;
              });
              this.comment = "";
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          this.$message.error("评论内容不能为空！");
        }
      } else {
        this.$message.push("/login");
      }
    },
    //生成从minNum到maxNum的随机数
    randomNum(minNum, maxNum) {
      switch (arguments.length) {
        case 1:
          return parseInt(Math.random() * minNum + 1, 10);
          break;
        case 2:
          return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);
          break;
        default:
          return 0;
          break;
      }
    },
  },
  created() {
    getOneFilm(this.$route.query.v_id).then((res) => {
      if (res.data.code == 0) {
        this.video = res.data.video;
      } else {
        this.$message.error("出错咯");
      }
    });
  },
};
</script>

<style lang="less" scoped>
.second-contrainer {
  width: 100%;
  .video-title {
    span {
      display: inline-block;
      font-size: 25px;
      font-weight: 500;
    }
  }
  .line {
    width: 100%;
    height: 1px;
    background-color: #ccc;
  }
  .top-contrainer {
    display: flex;
    justify-content: flex-start;
    width: 100%;
    .top-left {
      width: 40%;
      .video-img {
        img {
          width: 100%;
          max-height: 400px;
        }
      }
    }
    .top-right {
      margin-left: 5%;
      width: 55%;
      display: flex;
      flex-direction: column;
      justify-content: flex-start;
      align-items: flex-start;
      font-size: 15px;
      color: rgb(107, 102, 102);
      span:nth-child(n + 2) {
        margin-top: 5px;
      }
      .score {
        font-size: 25px;
        color: rgb(255, 90, 0);
      }
      .special {
        color: black;
      }
    }
  }
  .middle-contrainer {
    .sequel {
      width: 100%;
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      .sequel-item {
        font-size: 15px;
        color: black;
        text-decoration: none;
        width: 12%;
        margin-right: 30px;
        margin-top: 10px;
        display: inline-block;
        border: 1px solid rgb(221, 221, 221);
        border-radius: 5%;
        padding: 5px;
        &:hover {
          background-color: rgb(79, 116, 172);
        }
      }
    }
    p {
      text-indent: 2em;
    }
    textarea {
      width: 99%;
    }
    .submit-comment {
      margin-top: 15px;
    }
  }
}
</style>